<script>
import { debounce } from '@/utils'
export default {
  name: 'CButton',
  data() {
    return {
      loading: false
    }
  },
  render(h) {
    let click = this.$listeners.click
    if (click) {
      click = debounce(click)
    }
    return h('el-button', {
      props: {
        ...this.$attrs,
        loading: this.loading
      },
      on: {
        click: () => {
          if (click === undefined) return
          this.loading = true
          click().finally(() => {
            this.loading = false
          })
        }
      }
    }, [this.$scopedSlots.default()])
  }
}
</script>
